package org.shopen.puremvc.controller.startup
{
	import org.puremvc.as3.interfaces.INotification;
	import org.puremvc.as3.patterns.command.SimpleCommand;
	import org.puremvc.as3.utilities.statemachine.FSMInjector;
	import org.shopen.puremvc.ApplicationConstants;

	public class InjectFSMCommand extends SimpleCommand
	{
		override public function execute(notification:INotification):void
		{
			var fsm:XML = 
			<fsm initial={ApplicationConstants.STATE_WELCOMING_CLOSED}>
			   
			   <!-- WELCOMING [CLOSED] -->
			   <state name={ApplicationConstants.STATE_WELCOMING_CLOSED}>
			       <transition action={ApplicationConstants.ACTION_REQUEST_OPENING} target={ApplicationConstants.STATE_OPENING_CLOSED}/>
			       <transition action={ApplicationConstants.ACTION_REQUEST_CREATING} target={ApplicationConstants.STATE_CREATING_CLOSED}/>
			   </state>
			   
			   <!-- CREATING [CLOSED] -->
			   <state name={ApplicationConstants.STATE_CREATING_CLOSED} changed={ApplicationConstants.CHS_CREATING_CLOSED}>
			       <transition action={ApplicationConstants.ACTION_CANCEL} target={ApplicationConstants.STATE_WELCOMING_CLOSED}/>
			       <transition action={ApplicationConstants.ACTION_CREATE} target={ApplicationConstants.STATE_EDITING_NEW}/>
			   </state>
			   
			   <!-- OPENING [CLOSED] -->
			   <state name={ApplicationConstants.STATE_OPENING_CLOSED}>
			       <transition action={ApplicationConstants.ACTION_CANCEL} target={ApplicationConstants.STATE_WELCOMING_CLOSED}/>
			       <transition action={ApplicationConstants.ACTION_OPEN} target={ApplicationConstants.STATE_EDITING_SAVED}/>
			   </state>
			   
			   <!-- EDITING [SAVED] -->
			   <state name={ApplicationConstants.STATE_EDITING_SAVED}>
			       <transition action={ApplicationConstants.ACTION_REQUEST_CREATING} target={ApplicationConstants.STATE_CREATING_SAVED}/>
			       <transition action={ApplicationConstants.ACTION_REQUEST_OPENING} target={ApplicationConstants.STATE_OPENING_SAVED}/>
			   	   <transition action={ApplicationConstants.ACTION_CHANGE} target={ApplicationConstants.STATE_EDITING_CHANGED}/>
			   	   <transition action={ApplicationConstants.ACTION_REQUEST_CLOSING} target={ApplicationConstants.STATE_WELCOMING_CLOSED}/>
			   </state>
			   
			   <!-- OPENING [SAVED] -->
			   <state name={ApplicationConstants.STATE_OPENING_SAVED}>
			       <transition action={ApplicationConstants.ACTION_CANCEL} target={ApplicationConstants.STATE_EDITING_SAVED}/>
			       <transition action={ApplicationConstants.ACTION_OPEN} target={ApplicationConstants.STATE_EDITING_SAVED}/>
			   </state>
			   
			   <!-- CREATING [SAVED] -->
			   <state name={ApplicationConstants.STATE_CREATING_SAVED}>
			       <transition action={ApplicationConstants.ACTION_CANCEL} target={ApplicationConstants.STATE_EDITING_SAVED}/>
			       <transition action={ApplicationConstants.ACTION_CREATE} target={ApplicationConstants.STATE_EDITING_NEW}/>
			   </state>
			   
			   <!-- EDITING [NEW] -->
			   <state name={ApplicationConstants.STATE_EDITING_NEW}>
			       <transition action={ApplicationConstants.ACTION_REQUEST_CREATING} target={ApplicationConstants.STATE_CREATING_NEW}/>
			       <transition action={ApplicationConstants.ACTION_REQUEST_OPENING} target={ApplicationConstants.STATE_OPENING_NEW}/>
			   	   <transition action={ApplicationConstants.ACTION_REQUEST_SAVING} target={ApplicationConstants.STATE_SAVING_NEW}/>
			   	   <transition action={ApplicationConstants.ACTION_REQUEST_CLOSING} target={ApplicationConstants.STATE_WELCOMING_CLOSED}/>
			   	   <transition action={ApplicationConstants.ACTION_CHANGE} target={ApplicationConstants.STATE_EDITING_CHANGED}/>
			   </state>
			   
			   <!-- OPENING [NEW] -->
			   <state name={ApplicationConstants.STATE_OPENING_NEW}>
			       <transition action={ApplicationConstants.ACTION_CANCEL} target={ApplicationConstants.STATE_EDITING_NEW}/>
			       <transition action={ApplicationConstants.ACTION_OPEN} target={ApplicationConstants.STATE_EDITING_SAVED}/>
			   </state>
			   
			   <!-- CREATING [NEW] -->
			   <state name={ApplicationConstants.STATE_CREATING_NEW} changed={ApplicationConstants.CHS_CREATING_NEW}>
			       <transition action={ApplicationConstants.ACTION_CANCEL} target={ApplicationConstants.STATE_EDITING_NEW}/>
			       <transition action={ApplicationConstants.ACTION_CREATE} target={ApplicationConstants.STATE_EDITING_NEW}/>
			   </state>
			   
			   <!-- SAVING [NEW] -->
			   <state name={ApplicationConstants.STATE_SAVING_NEW}>
			       <transition action={ApplicationConstants.ACTION_CANCEL} target={ApplicationConstants.STATE_EDITING_NEW}/>
			       <transition action={ApplicationConstants.ACTION_SAVE} target={ApplicationConstants.STATE_EDITING_SAVED}/>
			   </state>
			   
			   <!-- EDITING [CHANGED] -->
			   <state name={ApplicationConstants.STATE_EDITING_CHANGED}>
			       <transition action={ApplicationConstants.ACTION_REQUEST_CLOSING} target={ApplicationConstants.STATE_SAVING_CLOSING_CHANGED}/>
			       <transition action={ApplicationConstants.ACTION_REQUEST_CREATING} target={ApplicationConstants.STATE_SAVING_CREATING_CHANGED}/>
			   	   <transition action={ApplicationConstants.ACTION_REQUEST_OPENING} target={ApplicationConstants.STATE_SAVING_OPENING_CHANGED}/>
			   	   <transition action={ApplicationConstants.ACTION_REQUEST_SAVING} target={ApplicationConstants.STATE_SAVING_CHANGED}/>
			   </state>
			   
			   <!-- SAVING_CLOSING [CHANGED] -->
			   <state name={ApplicationConstants.STATE_SAVING_CLOSING_CHANGED}>
			       <transition action={ApplicationConstants.ACTION_CANCEL} target={ApplicationConstants.STATE_EDITING_CHANGED}/>
			       <transition action={ApplicationConstants.ACTION_SAVE} target={ApplicationConstants.STATE_WELCOMING_CLOSED}/>
			   	   <transition action={ApplicationConstants.ACTION_DONT_SAVE} target={ApplicationConstants.STATE_WELCOMING_CLOSED}/>
			   </state>
			   
			   <!-- SAVING_CREATING [CHANGED] -->
			   <state name={ApplicationConstants.STATE_SAVING_CREATING_CHANGED}>
			       <transition action={ApplicationConstants.ACTION_CANCEL} target={ApplicationConstants.STATE_EDITING_CHANGED}/>
			       <transition action={ApplicationConstants.ACTION_SAVE} target={ApplicationConstants.STATE_CREATING_CLOSED}/>
			   	   <transition action={ApplicationConstants.ACTION_DONT_SAVE} target={ApplicationConstants.STATE_CREATING_CLOSED}/>
			   </state>
			   
			   <!-- SAVING_OPENING [CHANGED] -->
			   <state name={ApplicationConstants.STATE_SAVING_OPENING_CHANGED}>
			       <transition action={ApplicationConstants.ACTION_CANCEL} target={ApplicationConstants.STATE_EDITING_CHANGED}/>
			       <transition action={ApplicationConstants.ACTION_SAVE} target={ApplicationConstants.STATE_OPENING_CLOSED}/>
			   	   <transition action={ApplicationConstants.ACTION_DONT_SAVE} target={ApplicationConstants.STATE_OPENING_CLOSED}/>
			   </state>
			   
			   <!-- SAVING [CHANGED] -->
			   <state name={ApplicationConstants.STATE_SAVING_CHANGED}>
			       <transition action={ApplicationConstants.ACTION_CANCEL} target={ApplicationConstants.STATE_EDITING_CHANGED}/>
			       <transition action={ApplicationConstants.ACTION_SAVE} target={ApplicationConstants.STATE_EDITING_SAVED}/>
			   </state>
			</fsm>;
			
			// Create and inject the StateMachine 
			var injector : FSMInjector = new FSMInjector(fsm);
			injector.inject();
		}
	}
}